{extend name="base" /}
<!-- page specific plugin styles -->
{block name="plugin-styles"}
	<link rel="stylesheet" href="/static/ace/assets/css/colorbox.min.css" />
{/block}
<!-- inline styles related to this page -->
{block name="inline-styles"}{/block}
<!-- breadcrumb -->
{block name="breadcrumbs"}
<ul class="breadcrumb">
    <li>
        <i class="ace-icon fa fa-home home-icon"></i>
        <a href="{:url('Index/index')}">首页</a>
    </li>
    <li class="active">代理管理</li>
</ul>
<!-- /.breadcrumb -->
{/block}
<!-- PAGE CONTENT BEGINS -->
{block name="content"}
<div class="page-header">
    <h1>
		代理审核列表
	</h1>
</div>
<!-- /.page-header -->
<div class="clearfix tableTools-container">
    <form class="pull-left form-inline">
        <div class="form-group">
            <label class="sr-only" for="title">代理</label>
            <div class="input-group">
                <span class="input-group-addon">代理</span>
                <input type="text" class="form-control input-sm" name="title" placeholder="代理姓名或手机号">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label" for="title">审核状态</label>
            <select class="form-control input-sm" name="status" id="">
                <option value="2">待审核</option>
                <option value="1">已审核</option>
                <option value="3">未通过</option>
            </select>
        </div>
        <div class="form-group">
        	<button type="button" class="btn btn-xs btn-primary" id="searchTable">搜索</button>
        </div>
    </form>
</div>
<div class="table-responsive">
	<table class="table table-bordered" id="DynamicTable"></table>
</div>
<!-- /.table-responsive -->
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    审核备注
                </div>
            </div>
            <div class="modal-body">
                <textarea class="form-control" id="remark"></textarea>
            </div>
            <div class="modal-footer">
                <button class="btn btn-sm btn-success" onClick="examine()"> <i class="ace-icon fa fa-check"></i> save </button>
                <button class="btn btn-sm btn-danger" data-dismiss="modal"> <i class="ace-icon fa fa-times"></i> Close </button>
            </div>
        </div>
    </div>
</div>
{/block}
<!-- PAGE CONTENT ENDS -->
<!-- page specific plugin scripts -->
{block name="plugin-scripts"}
<script src="/static/ace/assets/js/jquery.dataTables.min.js"></script>
<script src="/static/ace/assets/js/jquery.dataTables.bootstrap.min.js"></script>
<script src="/static/ace/assets/js/jquery.colorbox.min.js"></script>
{/block}
<!-- inline scripts related to this page -->
{block name="related-scripts"}
<script type="text/javascript">
		var myTable = 
		$('#DynamicTable')
		.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
		.DataTable({
			"autoWidth": false,	//智能列宽处理
			"deferRender": true,	//延迟渲染以获得额外的初始化速度
			"info": true,	//表信息显示
			"lengthChange": false,	//更改每页记录数
			"ordering": false,	//排序功能
			"paging": true,	//启用或禁用表分页
			"processing": false,	//处理指标
			// "scrollX": false,	//水平滚动
			// "scrollY": false,	//垂直滚动
			"searching": false,	//搜索功能
			"serverSide": true,	//服务器端处理模式
			"stateSave": false,	//状态保存(页面重新加载时恢复表状态)
			"language": {
                "url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/Chinese.json"
            },
			"ajax": {
                "url": "/admin/agent/lists",
                "type": "POST",
                "data": function (d) {
                    d.title = $("input[name=title]").val();
                    d.status = $("select[name=status]").val();
                },
                "dataSrc": function (json) {
                    return json.data;
                }
            },
            "columns": [{
                "title": "编号",
                "data": "id"
            }, {
                "title": "姓名",
                "data": "name"
            }, {
                "title": "电话",
                "data": "tel"
            }, {
                "title": "微信号",
                "data": "weixin"
            }, {
                "title": "邮箱",
                "data": "email"
            }, {
                "title": "身份证号",
                "data": "idnum"
            }, {
                "title": "所在地址",
                "data": "addr"
            }, {
                "title": "推荐人",
                "data": "fname"
            }, {
                "title": "身份证截图",
                "data": "idpic1"
            }, {
                "title": "保证金截图",
                "data": "idpic2",
            }, {
                "title": "状态",
                "data": "status"
            }, {
                "title": "等级",
                "data": "grade"
            }, {
                "title": "申请时间",
                "data": "addtime"
            }, {
                "title": "操作",
                "data": "id"
            }],
            "columnDefs": [{
            	"className": "text-center",
            	"targets": [0,2,8,9,10,12,13]
            }, {
            	"render": function (data, type, row, meta) {
                    var _files =data.split(',');
                    var _html=""
                    for(var i=0;i<_files.length;i++){
                        if(i==0){
                            _html= _html + '<a class="btn btn-minier btn-warning" href="'+_files[i]+'" data-rel="colorbox">查看截图</a>';
                        }else{
                            _html= _html + '<a class="hide" href="'+_files[i]+'" data-rel="colorbox">查看截图</a>';
                        }
                        
                    }
            		return _html;
            	},
            	"targets": 8
            }, {
            	"render": function (data, type, row, meta) {
            		return '<a class="btn btn-minier btn-warning" href="'+data+'" data-rel="colorbox">查看截图</a>';
            	},
            	"targets": 9
            }, {
                "render": function (data, type, row, meta) {
                	if(data==1){
                        return '<span class="label label-success">已审核</span>';
                    }else if(data==2){
                        return '<span class="label label-warning">待审核</span>';
                    }else if(data==4){
                        return '<span class="label label-warning">已关停</span>';
                    }else{
                        return '<span class="label label-danger">未通过</span>';
                    }
                },
                "targets": 10
            },  {
                "render": function (data, type, row, meta) {
                    if(data==1){
                        return "品正商"
                    }else if(data==2){
                        return "品正商V"
                    }
                },
                "targets": 11
            }, {
            	"render": function (data, type, row, meta) {
                    if(row.status==2){
                        return  '<div class="btn-group">\
                            <button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-xs btn-success" data-rel="tooltip" title="通过" onClick="showModal('+data+',1)">\
                                <i class="ace-icon fa fa-check bigger-120"></i>\
                            </button>\
                            <button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-xs btn-danger"  data-rel="tooltip" title="不通过" onClick="showModal('+data+',2)">\
                                <i class="ace-icon fa fa-times bigger-120"></i>\
                            </button>\
                        </div>';
                    }else{
                       return  '<div class="btn-group">\
                            <button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-xs btn-success" disabled data-rel="tooltip" title="通过" onClick="showModal('+data+',1)">\
                                <i class="ace-icon fa fa-check bigger-120"></i>\
                            </button>\
                            <button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-xs btn-danger"  disabled data-rel="tooltip" title="不通过" onClick="showModal('+data+',2)">\
                                <i class="ace-icon fa fa-times bigger-120"></i>\
                            </button>\
                        </div>';
                    }
                },
                "targets": 13
            }],
            "createdRow": function( row, data, dataIndex ) {
            	console.log(row);
			},
            "initComplete": function( settings, json ) {
            	$("#DynamicTable").prev(".row").remove();
            	//add tooltip for small view
				$('[data-rel="tooltip"]').tooltip();
				$('[data-rel="colorbox"]').colorbox(colorbox_params);
			}
		});
        $("#searchTable").click(function () {
            myTable.draw();
        });

		var $overflow = '';
		var colorbox_params = {
			rel: 'colorbox',
			reposition:true,
			scalePhotos:true,
			scrolling:false,
			previous:'<i class="ace-icon fa fa-arrow-left"></i>',
			next:'<i class="ace-icon fa fa-arrow-right"></i>',
			close:'&times;',
			current:'{current} of {total}',
			maxWidth:'100%',
			maxHeight:'100%',
			onOpen:function(){
				$overflow = document.body.style.overflow;
				document.body.style.overflow = 'hidden';
			},
			onClosed:function(){
				document.body.style.overflow = $overflow;
			},
			onComplete:function(){
				$.colorbox.resize();
			}
		};

		
		$("#cboxLoadingGraphic").html("<i class='ace-icon fa fa-spinner orange fa-spin'></i>");//let's add a custom loading icon
		
		
		$(document).one('ajaxloadstart.page', function(e) {
			$('#colorbox, #cboxOverlay').remove();
		});

        

    // 查看
    function showModal(_id, _status){
        $("#myModal").data("id",_id);
        $("#myModal").data("status",_status);
    }
    // 审核
    function examine(){
        $.ajax({
            url: "/admin/agent/shenhe",
            type: 'POST',
            dataType: 'json',
            data: {
                id: $("#myModal").data("id"),
                status: $("#myModal").data("status"),
                beizhu: $("#remark").val()
            },
        })
        .done(function(json) {
            console.log("success");
            alert("审核成功");
            $("#myModal").modal('hide');
            myTable.draw();
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            console.log("complete");
        });
        
    }


</script>
{/block}